#pragma once
#include "DUniversal.h"
#include "../DWorld.h"
#include "../DVector3.h"
#include "DJointGroup.h"

namespace Skill
{
	namespace Ode
	{
		namespace Joints
		{	
			void DUniversal::CollectManagedMemory()
			{				
				_Axis1 = nullptr;
				_Axis2 = nullptr;
				_Anchor1 = nullptr;
				_Anchor2 = nullptr;
				DJoint::CollectManagedMemory();
			}
			DUniversal::DUniversal(DWorld^ world , DJointGroup^ group)
				:DJoint(world,group)
			{
				dWorldID w = world? world->_This : NULL;
				dJointGroupID g = group? group->_This : NULL;
				_SetPointer(dJointCreateUniversal(w,g),true);
			}			

			DVector3^ DUniversal::Anchor1::get()
			{
				if(!_Anchor1)
					_Anchor1 = gcnew DVector3();
				dJointGetUniversalAnchor(_This,_Anchor1->_This);
				return _Anchor1;
			}
			void DUniversal::Anchor1::set(DVector3^ value)
			{
				dJointSetUniversalAnchor(_This,value->_This[0],value->_This[1],value->_This[2]);
			}


			DVector3^ DUniversal::Axis1::get()
			{
				if(!_Axis1)
					_Axis1 = gcnew DVector3();
				dJointGetUniversalAxis1(_This,_Axis1->_This);
				return _Axis1;
			}
			void DUniversal::Axis1::set(DVector3^ value)
			{
				dJointSetUniversalAxis1(_This,value->_This[0],value->_This[1],value->_This[2]);
			}

			DVector3^ DUniversal::Axis2::get()
			{
				if(!_Axis2)
					_Axis2 = gcnew DVector3();
				dJointGetUniversalAxis2(_This,_Axis2->_This);
				return _Axis2;
			}
			void DUniversal::Axis2::set(DVector3^ value)
			{
				dJointSetUniversalAxis2(_This,value->_This[0],value->_This[1],value->_This[2]);
			}

			void DUniversal::SetParam(DJointParameters parameter, dReal value)
			{
				dJointSetUniversalParam(_This,(int)parameter, value);
			}
			dReal DUniversal::GetParam(DJointParameters parameter)
			{
				return dJointGetUniversalParam(_This,(int)parameter);
			}

			void DUniversal::AddTorques(dReal torque1, dReal torque2)
			{
				dJointAddUniversalTorques(_This,torque1,torque2);
			}

			DVector3^ DUniversal::Anchor2::get()
			{
				if(!_Anchor2)
					_Anchor2 = gcnew DVector3();
				dJointGetUniversalAnchor2(_This,_Anchor2->_This);
				return _Anchor2;
			}

			void DUniversal::GetAngles([OutAttribute] dReal %angle1, [OutAttribute] dReal %angle2)
			{
				dReal a1,a2;
				dJointGetUniversalAngles(_This,&a1,&a2);
				angle1 = a1;
				angle2 = a2;
			}
			dReal DUniversal::Angle1::get()
			{
				return dJointGetUniversalAngle1(_This);
			}
			dReal DUniversal::Angle2::get()
			{
				return dJointGetUniversalAngle1Rate(_This);
			}

			dReal DUniversal::Angle1Rate::get()
			{
				return dJointGetUniversalAngle2(_This);
			}
			dReal DUniversal::Angle2Rate::get()
			{
				return dJointGetUniversalAngle2Rate(_This);
			}
		}
	}
}